﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace School
{
    class Course
    {
        public string Name { get; set; }
        public HashSet<Student> Students { get; set; }

        public Course(string name)
        {
            this.Name = name;
        }

        public void AddStudent(Student studentToAdd)
        {
            if (this.Students.Contains(studentToAdd))
            {
                throw new InvalidOperationException("One student is allowed to subscribe only once");
            }
            CheckStudentNumber();
            this.Students.Add(studentToAdd);
        }
  
        private void CheckStudentNumber()
        {
            if (this.Students.Count > 30)
            {
                throw new InvalidOperationException("There are more than 30 Students already signed");
            }
        }

        public void RemoveStudent(Student studentToRemove)
        {
            if (!this.Students.Contains(studentToRemove))
            {
                throw new InvalidOperationException("Student is not subscribed to the course");
            }
            CheckStudentNumber();
            this.Students.Remove(studentToRemove);
        }
    }
}
